package main

import (
	"fmt"
	"strconv"
	"sync"
)
//
//var m = make(map[string]int)
//
//func get(key string) int {
//	return m[key]
//}
//
//func set(key string, value int) {
//	m[key] = value
//}

var m = sync.Map{}

func main() {
	//wg := sync.WaitGroup{}
	//for i := 0; i < 20; i++ {
	//	wg.Add(1)
	//	go func(n int) {
	//		key := strconv.Itoa(n)//将数字转化为字符串
	//		set(key, n)
	//		fmt.Printf("k=:%v,v:=%v\n", key, get(key))
	//		wg.Done()
	//	}(i)
	//}
	//wg.Wait()





	//安全的map
	wg := sync.WaitGroup{}
	wg.Add(20)
	for i := 0; i < 20; i++ {

		go func(n int) {
			key := strconv.Itoa(n)
			m.Store(key, n)
			value, _ := m.Load(key)
			fmt.Printf("k=:%v,v:=%v\n", key, value)
			wg.Done()
		}(i)
	}
	wg.Wait()

}
